﻿using Infrastructure.Interface;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace Domain
{
    [JsonObject]
    [Serializable]
    public class EntityBase: IEntity
    {
        /// <summary>
        /// ID
        /// </summary>
        [Key]
        [Required]
        public Guid ID { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>      
        public DateTime? CreateTime { get; set; }


        /// <summary>
        /// 备注
        /// </summary>      
        public string ReMark { get; set; }
             

        /// <summary>
        /// 获取自身的ID是否为Empty
        /// </summary>
        public bool IsEmptyID()
        {
            return this.ID.Equals(Guid.Empty);
        }

       
        /// <summary>
        /// 对实体进行url解码
        /// 此方法只会对string类型的属性进行URL解码
        /// </summary>
        public void URLDecode()
        {
            this.GetType()
                .GetProperties()
                .Where(p => p.PropertyType.Equals(typeof(string)))
                .ToList()
                .ForEach(p => p.SetValue(this, HttpUtility.UrlDecode(p.GetValue(this, null) as string), null));

        }

        /// <summary>
        /// ID
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return string.Format("ID={0}", this.ID);
        }

    }
}
